#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
using namespace std;
const int MAXN = 1e5+7;
int p[MAXN];
struct node {
    int x, y;
} point[MAXN];
bool cmp(node a, node b) {
    if (a.x!=b.x) return a.x>b.x;
    return a.y>b.y;
}
bool cmp1(int a, int b) {
    return a>b;
}
int main(int argc, char** argv) {
    int n,m;
    cin>>n>>m;
    for (int i=0; i<n; ++i) scanf("%d", p+i);
    for (int i=0, x, y; i<m; ++i) {
        scanf("%d %d", &x, &y);
        point[i].x = x; point[i].y = y;
    }
    sort(p, p+n, cmp1);
    sort(point, point+m, cmp);
    int mark = 0;
    long long res = 0;
    bool flag=false;
    priority_queue<int> q;
    for (int i=0; i<n; ++i) {
        while (mark<m && point[mark].x>=p[i]) {
            q.push(-point[mark].y);
            ++mark;
        }
        if (!q.empty()) {
            res += (-q.top()); q.pop();
        }
        else flag=true;
    }
    if(!flag) cout<<res<<endl;
    else cout<<-1<<endl;
    return 0;
}
